<?php
class ControllerAccountTransactiondetailed extends Controller {
	public function index() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->link('account/transaction', '', 'SSL');
			
	  		$this->redirect($this->url->link('account/login', '', 'SSL'));
    	}		
		
		$this->language->load('account/transaction');

		$this->document->setTitle($this->language->get('heading_title'));
        if (isset($this->request->get['id'])) {
		$id = $this->request->get['id'];
		} else {
			$id = NULL;
		}  
      	$this->data['breadcrumbs'] = array();

      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
        	'separator' => false
      	); 

      	$this->data['breadcrumbs'][] = array(       	
        	'text'      => $this->language->get('text_account'),
			'href'      => $this->url->link('account/account', '', 'SSL'),
        	'separator' => $this->language->get('text_separator')
      	);
		
      	$this->data['breadcrumbs'][] = array(       	
        	'text'      => $this->language->get('text_transaction'),
			'href'      => $this->url->link('account/transaction', '', 'SSL'),
        	'separator' => $this->language->get('text_separator')
      	);
      $this->data['breadcrumbs'][] = array(       	
        	'text'      => $this->language->get('billsdetailed'),
			'href'      => $this->url->link('account/transactiondetailed','&id='.$id, 'SSL'),
        	'separator' => $this->language->get('text_separator')
      	);
		
		$this->load->model('account/transaction');

    	$this->data['heading_title'] = $this->language->get('billsdetailed');
		
		$this->data['name'] = $this->language->get('name');
		$this->data['quantity'] = $this->language->get('quantity');
		$this->data['amount'] = $this->language->get('amount');		
                
		$this->data['text_total'] = $this->language->get('text_total');
		$this->data['text_empty'] = $this->language->get('text_empty');
		
		$this->data['button_continue'] = $this->language->get('button_continue');
				
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}		
		$results = $this->model_account_transaction->getTransactions($this->customer->getId());
                  if($results!=null)
                {                 
                    foreach ($results as $result) {
                       $sum = 0;                     
                       $details = $this->model_account_transaction->getdetailedbills($id);
                        foreach ($details as $detail){
                       $sum = $sum + $detail['amount'];
                        }		
			$this->data['customertamount'] = $sum;
		}
                }	
		 $results = $this->model_account_transaction->getdetailedbills($id);
                $bills_total = count($results);
                  foreach ($results as $result) {
			$this->data['detailed'][] = array(
                          'name'       =>  $result['name'],
                          'amount'     =>  $result['amount'],
                          'quantity'   =>  $result['quantity'],
                        );
		}	

		$pagination = new Pagination();
		$pagination->total = $bills_total;
		$pagination->page = $page;
		$pagination->limit = 10; 
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('account/transactiondetailed', 'page={page}', 'SSL');
			
		$this->data['pagination'] = $pagination->render();
		
		$this->data['total'] = $this->currency->format($this->customer->getBalance());
		
		$this->data['continue'] = $this->url->link('account/account', '', 'SSL');
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/transactiondetailed.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/account/transactiondetailed.tpl';
		} else {
			$this->template = 'default/template/account/transactiondetailed.tpl';
		}
		
		$this->children = array(
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'	
		);
						
		$this->response->setOutput($this->render());		
	} 		
}
?>